<#assign crudUrl="crud.ftl" />

<#macro page title="" encoding="utf-8" beginPath="/crud/">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=${encoding}">
<!-- crud js related -->
<script type="text/javascript" src="${beginPath}js/crud.valid.js"></script>
<!-- jquery js related -->
<script type="text/javascript" src="${beginPath}js/jquery.validate.js"></script>
<script type="text/javascript" src="${beginPath}js/niceforms.js"></script>

<!-- css related -->
<link href="${beginPath}css/niceforms-default.css" rel="stylesheet" type="text/css" />

<title>${title}</title>

	<script type="text/javascript">
	$(function () {
		// nice forms
		init_niceform();
	});
	</script>
	
</head>
<body>

<#nested>

</body>
</html>
</#macro>
<#-- End Crud Macro: Page -->

<#macro pagination style="scott" targetUrl="#?1=1&" totalCount=8>
<#if page?exists>
<#assign list = page.resultList />

<#assign cp = page.currentPage />
<#assign npp = page.numPerPage />

<#assign begin = cp - totalCount/2 />

<#assign totalRows = page.totalRows />
<#assign totalPages = page.getTotalPages() />

<div class="${style}">
	<span class=""> 
		<a href="${targetUrl}cp=1" title="First Page"><<</a>
	</span>
	<#assign count = 0 />
	<#list begin..totalPages as pp>
		<#if begin <= 0>
			<#assign begin = begin + 1 />
		<#else>
			<#if count > 8>
				<#break>
			<#else>
				<#if begin == cp>
					<span class="current" title="Current Page">${cp}</span>
				<#else>
					<a href="${targetUrl}cp=${begin}" title="Page ${begin}">${begin}</a>
				</#if>
				<#assign begin = begin + 1 />
				<#assign count = count + 1 />
			</#if>
		</#if>
	</#list>
	...
	<#if cp == totalPages>
		<span class="current" title="Current Page">${cp}</span>
	<#else>
		<a href="${targetUrl}cp=${totalPages}" title="Last Page">${totalPages}</a>
	</#if>

	<#if cp != totalPages>
		<a href="${targetUrl}cp=${cp + 1}" title="Next Page"> > </a>
	<#else>
		<a href="${targetUrl}cp=${cp}" title="Next Page"> > </a>
	</#if>
</div>
</#if>
</#macro>
<#-- End Crud Macro: Pagination -->